<?
include("../lib/config.php");
(int) $nik 	= $HTTP_GET_VARS['nik'];
$op			= $HTTP_GET_VARS['op'];
(int) $no	= $HTTP_GET_VARS['no'];

if($op == "edit"){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("WITH limit AS (
	SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, *, CONVERT(CHAR(12), Track_start, 103) TrackStart, 
	CONVERT(CHAR(12), Track_end, 103) TrackEnd 
	FROM VTrackRecord WHERE NIK='$nik' ) SELECT * FROM limit WHERE No='$no'",$conn);
	$row	= mssql_fetch_array($query);
}
else{
	$Faction = "../lib/save.php";
	$Vbutton = "Simpan";
}

include("../header.php");
?>
<script type="text/javascript">
	function LoadFocus(){
		document.forms[0].elements[0].focus();
	}
	
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};

	function Validate(){
		if(document.FEmployee.nik.value == "")
		{
			alert("Field : NIK tidak boleh kosong ...");
			document.FEmployee.nik.focus();
			return false;
		}//*/

		if(document.FEmployee.track_start.value == "")
		{
			alert("Field : Track Start tidak boleh kosong ...");
			document.FEmployee.track_start.focus();
			return false;
		}

		if(document.FEmployee.track_end.value == "")
		{
			alert("Field : Track End tidak boleh kosong ...");
			document.FEmployee.track_end.focus();
			return false;
		}
		
		if(document.FEmployee.client.value == "")
		{
			alert("Field : Client tidak boleh kosong ...");
			document.FEmployee.client.focus();
			return false;
		}

		if(document.FEmployee.product.value == "")
		{
			alert("Field : Product tidak boleh kosong ...");
			document.FEmployee.product.focus();
			return false;
		}

		if(document.FEmployee.project.value == "")
		{
			alert("Field : Project tidak boleh kosong ...");
			document.FEmployee.project.focus();
			return false;
		}
		
		if(document.FEmployee.job_desc.value == "")
		{
			alert("Field : Job Description tidak boleh kosong ...");
			document.FEmployee.job_desc.focus();
			return false;
		}

		document.FEmployee.submit();
		
	}
	
	function show_popup(page)
	{
		child = open
		(
			"frm_list_emp.php",
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}
</script>
</head>

<body onLoad="Javascript:LoadFocus();">
<form name="FEmployee" method="post" action="<?=$Faction?>">
	<table width="93%" class="table_indent2" style="border:none;">
	<tr>
	 <td colspan="2" class="line_bottom">&nbsp;&nbsp;<b>TRACK RECORD</b></td>
	</tr>
	<tr>
	</table>
<table width="100%" cellpadding="">
 <tr>
  <td colspan="2">
  </td>
 </tr>
 <tr>
  <td>&nbsp;</td>
 </tr>
 <tr>
  <td width="150"><b>NIK</b></td>
  <td>: <input type="text" readonly="" maxlength="10" value="<?=$nik?>" style="font-weight:bold;" class="text" name="nik" /> <span class="required">*</span>
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup()'><img src='../images/people.png' border=0></a>";
		}
	?>
  </td>
 </tr>
 <tr>
  <td width="150"><b>Nama</b></td>
  <td>: <input type="text" readonly="" size="50" value="<?=$row[Nama]?>" style="font-weight:bold;" class="text" name="nama" /> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Track Start</td>
  <td>: <input type="text" maxlength="10" value="<?=$row[TrackStart]?>"  class="text" size="11" name="track_start"/> <span class="required">*</span> <a href="javascript:calA.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> </td>
 </tr>
 <tr>
  <td>Track End</td>
  <td>: <input type="text" maxlength="10" value="<?=$row[TrackEnd]?>"  class="text" size="11" name="track_end"/> <span class="required">*</span> <a href="javascript:calB.popup();"><img src="../../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> </td>
 <tr>
  <td valign="top">Client</td>
  <td valign="top">&nbsp; 
  <textarea cols="45" rows="5" name="client"><?=$row[Client]?></textarea>
  <span class="required">*</span></td>
 <tr>
  <td valign="top">Product</td>
  <td valign="top">&nbsp; 
  <textarea cols="45" rows="5" name="product"><?=$row[Product]?></textarea>
  <span class="required">*</span></td>
 </tr>
 <tr>
  <td valign="top">Project</td>
  <td valign="top">&nbsp; 
  <textarea cols="45" rows="5" name="project"><?=$row[Project]?></textarea>
  <span class="required">*</span></td>
 </tr>
  <td valign="top">Job Description</td>
  <td valign="top">&nbsp; 
  <textarea cols="45" rows="5" name="job_desc"><?=$row[Job_Desc]?></textarea>
  <span class="required">*</span></td>
 </tr>
 <tr>
  <td>&nbsp;</td>
  <td><br><br />
  <input type="hidden" name="cat" value="track_record" />
  <input type="hidden" name="no" value="<?=$row[No]?>" />
  <input type="button" value="Batal" onClick="Javascript:history.back()" class="button" /><input type="button" value="Simpan" class="button" onClick="Javascript:Validate();" />
  </td>
 </tr>
</table>
</form>
</td>
</tr>
<tr>
 <td colspan="2" style="border:none;"><br /><? include("../footer.php"); ?></td>
</tr>
</table>
</body>
</html>
<script type="text/javascript">

var f = document.forms[0];
MaskInput(f.track_start,"99/99/9999");
MaskInput(f.track_end,"99/99/9999");
//]]>
</script>
<script type="text/javascript">
// script untuk popup calendar
	var calA = new calendar1(document.forms[0].elements['track_start']);
	calA.year_scroll = true;
	calA.time_comp = false;	
	var calB = new calendar1(document.forms[0].elements['track_end']);
	calB.year_scroll = true;
	calB.time_comp = false;	
</script>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>
